package Meta

import (
	"db2s/ETL"
	"db2s/global"
	"db2s/parDef"
	"db2s/ref"
)

type (
	IndexColumnMe struct {
		ColumnType string `json:"columnType"`
		ColumnName string `json:"columnName"`
		ColumnSeq  string `json:"columnSeq"`
		IndexSeq   string `json:"indexSeq"`
	}
	NameColumnMe struct {
		Schema        string          `json:"databaseName"`
		Table         string          `json:"tableName"`
		IndexName     string          `json:"indexName"`
		Column        []IndexColumnMe `json:"Column"`
		Null          string          `json:"null"`
		SubPart       string          `json:"subPart"`
		AutoIncrement string          `json:"autoIncrement"`
		NonUnique     string          `json:"nonUnique"`
		Cardinality   int64           `json:"cardinality"`
		ColumnKey     string          `json:"columnKey"`
		IndexCategory string          `json:"indexCategory"`
	}
)

func (ma Meta) gIndexMeEr(drive string) (ter IndexEr, err error) {
	if ter, err = NewMetaIndexMe(drive); err != nil {
		return
	}
	return
}

func (ma Meta) nameColumnMeta() (meta any, err error) {
	var ter IndexEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.gIndexMeEr(v); err != nil {
			return
		}
		if result, err = ter.NameColumn(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ETL.SMap))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("nameColumnMeta", err)
		return
	}
	return
}
func (ma Meta) keyChoose() (meta any, err error) {
	var ter IndexEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.gIndexMeEr(v); err != nil {
			return
		}
		if result, err = ter.KeyChoose(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ETL.SMap))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("nameColumnMeta", err)
		return
	}
	return
}
func (ma Meta) nameToColumnClip() (meta any, err error) {
	var ter IndexEr
	if meta, err = parDef.CallMethod(ma.Drive, ma.Join, func(k int, v string) (result global.Return, err error) {
		if ter, err = ma.gIndexMeEr(v); err != nil {
			return
		}
		if result, err = ter.NameToColumnClip(parDef.CtxBackground(parDef.GeneralReadMethodParameter(ma.Parameter1[k], nil, ETL.SMap))); err != nil {
			return
		}
		return
	}); err != nil {
		err = ref.ErrAddPrintf("nameColumnMeta", err)
		return
	}
	return
}
func (ma Meta) GetNameColumnMetaS() (result any, err error) {
	return ma.nameColumnMeta()
}
func (ma Meta) GetKeyChooseS() (result any, err error) {
	return ma.keyChoose()
}
func (ma Meta) GetNameToColumnClipST() (result any, err error) {
	return ma.nameToColumnClip()
}
